//
//  JXBag.m
//  Open Lottery
//
//  Created by Shon on 8/11/09.
//  Copyright 2009 Praxxium Systems, LLC. All rights reserved.
//

#import "JXBag.h"


@implementation JXBag

@synthesize rangeStart, rangeEnd, randomNumberGenerator;

-(id)initWithRangeStart:(uint8)s rangeEnd:(uint8)e  drawCount:(uint8)c {
    uint8 i;
    drawCount = c;
    if(s<=e) { rangeStart = s; rangeEnd = e; }
    else { rangeStart = e; rangeEnd = s; }
    numbers = [NSMutableArray arrayWithCapacity:e-s+1];
    for(i=s; i<=e; i++) [numbers replaceObjectAtIndex:i withObject:[NSNumber numberWithUnsignedChar:i]];
}

-(NSArray *)drawNumbers {
    uint8 i;
    NSNumber *nbr;
    NSMutableArray *choices = [[[NSMutableArray arrayWithCapacity:drawCount] retain] autorelease];
    for(i=0; i<drawCount; i++) {
        nbr = [numbers objectAtIndex:(NSUInteger)([rng nextNormalized]*(double)[numbers count])];
        [choices replaceObjectAtIndex:i withObject:nbr];
    }
    
    return choices;
}

@end
